<!DOCTYPE html>
<html lang='zh-CN'>
<head>
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='代码托管,git,Git@OSC,开源,项目管理,版本控制,开源代码,代码分享,项目协作,开源项目托管,免费代码托管,Git代码托管,Git托管服务' name='Keywords'>
<meta content='中国源代码托管(Git@OSC)是开源中国社区团队推出的基于Git的快速的、免费的、稳定的在线代码托管平台,不限制私有库和公有库数量.' name='Description'>
<title>
大项目/Rbac.class.php · 后盾网马震宇 / c47_teacher - 代码托管 - 开源中国社区
</title>
<link href="/assets/favicon-29e5aa12ede960b740afd05cad113944.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />
<meta content='git.oschina.net/hdmzy/c47_teacher git https://git.oschina.net/hdmzy/c47_teacher.git' name='go-import'>
<link href="/assets/application-3ea8b7d1e54db1c072b00097c92aadca.css" media="screen" rel="stylesheet" type="text/css" />
<script src="/assets/application-f8bdea7f4f584cdf00356dce9b48a6cf.js" type="text/javascript"></script>

<meta content="authenticity_token" name="csrf-param" />
<meta content="rq516QD5uAYT3oeOPlXvLrHxPkGcFI4G+bIbBkNuOaU=" name="csrf-token" />
<script type="text/javascript">
//<![CDATA[
window.gon = {};gon.gravatar_url="https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=mm";
//]]>
</script>
<!--[if lt IE 10]>
<script>
    window.location.href = "/incompatible.html"
</script>
<![endif]-->
</head>

<script src="/assets/projects/app-874a23db0ccb4caf2791d1a30405bd67.js" type="text/javascript"></script>
<body class='ui_basic project'>
<script>
  $(function() {
    GitLab.GfmAutoComplete.dataSource = "/hdmzy/c47_teacher/autocomplete_sources"
    GitLab.GfmAutoComplete.Emoji.assetBase = '/assets/emoji'
    GitLab.GfmAutoComplete.setup();
  });
</script>

<header class='ui grey menu grid page fixed noborder' id='git-header-nav'>
<div class='git-header'>
<div class='item' style='padding: 0'>
<img class='ui inline image' src='/logo.gif' style='height: 30px; padding-left: 1rem'>
</div>
<div class='item gitosc-logo'>
<a href="/">Git@OSC
</a></div>
<a href="/explore/recommend" class="item" style="font-size: 1.05rem">发现</a>
<a href="/oschina/git-osc/wikis/Home" class="item" style="font-size: 1.05rem">帮助</a>
<a href="/oschina/git-osc/issues" class="item" style="font-size: 1.05rem">建议</a>
<a href="http://www.oschina.net/" class="item" style="font-size: 1.05rem" target="_blank">社区</a>
<form accept-charset="UTF-8" action="/search" class="item search_padding" id="projects-search-form" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>
<div class='ui icon left mini input'>
<input autocomplete="off" id="search_top-search-input" name="search" placeholder="搜索项目..." style="border: 0px; background-color: #efefef" type="text" />
<i class='search link icon' id='projects-search'></i>
<input id="group_id" name="group_id" type="hidden" />
<input id="project_id" name="project_id" type="hidden" value="291209" />
</div>
</form>

<script>
  $('#projects-search').click(function(){
     $('#projects-search-form').submit();
  });
  // Author: Zoker, Date: 15.02.15, Note: 搜索框焦点背景色更改
  $('#search_top-search-input').click(function(){
    document.getElementById("search_top-search-input").style.backgroundColor = '#eaeaea'
  });
  $('#search_top-search-input').blur(function(){
    document.getElementById("search_top-search-input").style.backgroundColor = '#efefef'
  });
  // End
</script>


<div class='right menu userbar' id='git-nav-user-bar'>
<a href="/signup" class="item">注册
</a><a href="/login" class="item">登录
</a>
</div>
</div>
</header>
<script>
  var $dropdown = $('#git-nav-user-bar .ui.dropdown');
  $dropdown.dropdown({on: 'hover'});
</script>

<div class='ui grid page middle aligned' style='margin-top: 4.5rem;'>
<div class='row' id='oneclick_login_by_osc' style='display:none;padding-top:0;'>
<div class='column content'>
<div class='ui blue message alertmsg'>
检测到您已登录开源中国，是否一键登录Git？
<a href="/osc_login" class="ui button mini blue" data-method="post" rel="nofollow"><i class='icon-hand-right'></i>
一键登录
</a></div>
</div>
</div>
<script>
  $(document).ready(function(){
    $.get("/osc_login", function(data){
      if(data == 1)
        $("#oneclick_login_by_osc").show();
    });
  });
</script>
</div>

<!--[if lt IE 10]>
<script>
  window.location.href = "/incompatible.html"
</script>
<![endif]-->

<div class='ui grid page aligned' id='git-project-title'>
<div class='row'>
<div class='seven wide column'>
<h2 class='ui header' style='font-weight: 200'>
<i class='octicon octicon-repo'></i>
<span><a href="/hdmzy" class="author">后盾网马震宇</a> / <a href="/hdmzy/c47_teacher" class="repository" style="padding-bottom: 0px">c47_teacher</a><a href="/languages/PHP" class="ui small label" id="project-language" target="_blank">PHP</a>
<script id='project-languages' type='x-template'>
<table class='ui celled table' style='width: 600px;height: 200px;'>
<tbody>
<tr>
<td>
<strong>PHP</strong>
</td>
<td>
<div class='ui progress success'>
<div class='bar' style='width: 62.632%'></div>
</div>
</td>
<td>
62.63%
</td>
</tr>

<tr>
<td>
<strong>CSS</strong>
</td>
<td>
<div class='ui progress success'>
<div class='bar' style='width: 29.686%'></div>
</div>
</td>
<td>
29.69%
</td>
</tr>

<tr>
<td>
<strong>JavaScript</strong>
</td>
<td>
<div class='ui progress success'>
<div class='bar' style='width: 7.681%'></div>
</div>
</td>
<td>
7.68%
</td>
</tr>


</tbody>
</table>
</script>
<style>
  #project-language{
    font-weight: bold;
  }
</style>
<script>
  var languages = $('#project-languages').html();
  $("#project-language").popup({html: languages, lastResort: 'bottom center'});
</script>
</span>
</h2>
</div>
<div class='nine wide column right aligned middle aligned' id='git-project-operation'>
<div class='ui mini buttons basic'>
<a href="/hdmzy/c47_teacher/widget" class="ui black button"><i class='icon bookmark'></i>挂件
</a></div>
<span class='ui mini buttons basic watch-container'>
<a href="/login" class="ui button watch" title="登录以 Watch 这个项目"><i class='icon unhide'></i>
Watch
</a><a href="/hdmzy/c47_teacher/watchers" class="ui button social-count">2</a>
</span>
<span class='ui mini buttons basic star-container'>
<a href="/login" class="ui button star" title="登录以 Star 这个项目"><i class='empty star icon'></i>
Star
</a><a href="/hdmzy/c47_teacher/stargazers" class="ui button social-count">1
</a></span>
</div>
</div>
<div class='row' id='fetch-code-message' style='padding-top: 0px; display: none'>
<div class='sixteen wide column'>
<i class='help circle icon'></i>
<div class='ui green message status-color'>
<i class='close icon'></i>
<div class='header status-title'>
正在拉取代码...
</div>
<span class='status-message'>
后台正在拉取代码(会删除你所作的修改),拉取完成后，页面会自动刷新
</span>
</div>
</div>
</div>
</div>
<script>
  (function() {
    var t;
  
    t = 5;
  
    $(".fetch-code, .popup-github").popup({
      inline: true,
      hoverable: true,
      position: "right center",
      delay: {
        show: 400,
        hide: 100
      }
    });
  
    $(".fetch-code").click(function(e) {
      $('.ui.modal.fetch-code-modal').modal('show');
      $('.ui.modal.fetch-code-modal .ui.button.negative').click(function(e) {
        return $('.ui.modal.fetch-code-modal').modal('hide');
      });
      return $('.ui.modal.fetch-code-modal .ui.button.positive').click(function(e) {
        $('.ui.modal.fetch-code-modal').modal('hide');
        return $.ajax({
          type: "POST",
          url: "/hdmzy/c47_teacher/fork",
          timeout: 20000,
          dataType: 'json',
          data: {
            "fetch_code": 1
          },
          beforeSend: function() {
            $(".fetch-code").addClass("loading");
            return $("#fetch-code-message").show();
          },
          complete: function() {
            return $(".fetch-code").removeClass("loading");
          },
          success: function(data, textStatus, jqXHR) {
            var iid;
  
            if (data.status === 1) {
              $("#fetch-code-message .status-title").text("代码拉取完成");
              $("#fetch-code-message .status-message").text("页面将在" + t + "秒之后自动刷新...");
              return iid = setInterval(function() {
                if (--t >= 0) {
                  return $("#fetch-code-message .status-message").html("页面将在" + t + "秒之后自动刷新...<a class='mini ui green button' href='javascript:location.reload();' style='float:right;margin-top: 0px;'>立即刷新</a>");
                } else {
                  clearInterval(iid);
                  return location.reload();
                }
              }, 1000);
            } else {
              $("#fetch-code-message .status-color").removeClass("green").addClass("red");
              $("#fetch-code-message .status-title").text("代码拉取出错");
              $("#fetch-code-message .status-message").text("错误原因: " + data.message);
              return setTimeout(function() {
                $("#fetch-code-message").hide();
                return $("#fetch-code-message .status-color").removeClass("red").addClass("green");
              }, 5000);
            }
          },
          error: function(jqXHR, textStatus, errorThrown) {
            $("#fetch-code-message .status-color").removeClass("green").addClass("red");
            $("#fetch-code-message .status-title").text("代码拉取出错");
            $("#fetch-code-message .status-message").text("错误原因: 拉取超时");
            return setTimeout(function() {
              $("#fetch-code-message").hide();
              return $("#fetch-code-message .status-color").removeClass("red").addClass("green");
            }, 5000);
          }
        });
      });
    });
  
  }).call(this);
</script>

<div class='ui grid page middle aligned' id='git-project-nav'>
<div class='ui small secondary pointing menu' id='git-project-menu' style='text-align: center;'>
<a href="/hdmzy/c47_teacher" class="item active">代码
</a><div class='ui dropdown item' id='git-versions'>
版本
<i class='dropdown icon' style='float: none;'></i>
<div class='ui vertical menu'>
<a href="/hdmzy/c47_teacher/branches/recent" class="item ">分支
<span class='ui small label'>1</span>
</a><a href="/hdmzy/c47_teacher/tags" class="item ">标签
<span class='ui small label'>0</span>
</a><a href="/hdmzy/c47_teacher/graph/master" class="item ">项目网络
</a><a href="/hdmzy/c47_teacher/commits/master" class="item ">提交记录
</a></div>
</div>
<a href="/hdmzy/c47_teacher/pulls" class="item ">Pull Requests
<span class='ui mini label'>0</span>
</a><a href="/hdmzy/c47_teacher/issues" class="item ">Issues
<span class='ui mini label'>0</span>
</a><a href="/hdmzy/c47_teacher/attach_files" class="item ">附件
<span class='ui mini label'>0</span>
</a><a href="/hdmzy/c47_teacher/wikis/home" class="item ">Wiki
<span class='ui mini label'>1</span>
</a><a href="/hdmzy/c47_teacher/repository/stats" class="item ">统计
</a><a href="/hdmzy/c47_teacher/code_analysis" class="item ">质量分析
</a><a href="/hdmzy/c47_teacher/paas" class="item ">项目演示
</a></div>
</div>
<script>
  $('#git-versions.dropdown').dropdown();
  $.post("/hdmzy/c47_teacher/access", {}, function(ret) {});
</script>

<div class='ui page grid middle aligned' id='git-project'>
<div class='row' id='git-detail-clone'>
<div class='ten wide column'>
c47_teacher
——
<a href="/hdmzy/c47_teacher#git-readme" style="font-size: 0.9rem">查看更多</a>
</div>

<div class='six wide column'>
<div class='input-prepend project_clone_holder'>
<div class='ui mini buttons basic'>
<div class='ui black button switch active' data-clone='https://git.oschina.net/hdmzy/c47_teacher.git' id='switch-url'>HTTPS</div>
<div class='ui button switch' data-clone='git@git.oschina.net:hdmzy/c47_teacher.git'>SSH</div>
</div>
<div class='mini ui icon input'>
<input class="one_click_select" id="project_clone" name="project_clone" onfocus="this.select()" readonly="readonly" style="width: 100%; padding: 0.35em 0.5em" type="text" value="https://git.oschina.net/hdmzy/c47_teacher.git" />
<i class='copy icon js-zeroclipboard popup' data-clipboard-text='https://git.oschina.net/hdmzy/c47_teacher.git' data-copied-hint='已复制!' data-copy-hint='复制到剪贴板' id='copy_url' style='cursor:pointer; padding-top: 0.47em;'></i>
</div>
</div>
<style>
  .project_clone_holder{
  
  }
  .input-prepend>.ui.buttons>.button{
    padding: 0.43em 0.6em;
    font-size: 0.8rem;
  }
</style>
</div>

</div>
<div class='row' id='git-project-bread'>
<div class='ui horizontal list'>
<div class='item'>
<a href="/hdmzy/c47_teacher/repository/archive?ref=master" class="ui mini button basic" style="color: #666 !important; background-image: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.05));"><i class='icon download'></i>
ZIP
</a></div>
<div class='item' style='margin-left: 0'>
<form accept-charset="UTF-8" action="/hdmzy/c47_teacher/refs/switch" class="project-refs-form chzn-small" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>
<select class="project-refs-select chosen" id="ref" name="ref"><optgroup label="Branch"><option value="master" selected="selected">master</option></optgroup><optgroup label="Tag"></optgroup></select>
<input id="destination" name="destination" type="hidden" value="tree" />
<input id="path" name="path" type="hidden" value="大项目/Rbac.class.php" />
</form>

<style>
  .project-refs-form .chzn-container .chzn-drop .chzn-search input {
    min-width: 165px;
  }
  .project-refs-form .chzn-container .chzn-drop {
    min-width: 180px;
  }
  #ref_chzn a.chzn-single>span{
    font-weight: bold;
  }
  #ref_chzn{
    padding-left: 0rem !important;
    margin-bottom: 0rem !important;
  }
</style>

</div>
<div class='item breadcrumb_path' style='margin-left: 0; padding-left: 0'>
<div class='ui breadcrumb path' id='git-bread_font'>
<a href="/hdmzy/c47_teacher/tree/master" class="section repo-name" data-direction="back" style="font-weight: bold">c47_teacher
</a><div class='divider'>
/
</div>
<a href="/hdmzy/c47_teacher/tree/master/%E5%A4%A7%E9%A1%B9%E7%9B%AE" class="section" data-direction="back"><span class='cblue'>
大项目
</span>
</a><div class='divider'>
/
</div>
<strong>
Rbac.class.php
</strong>
</div>

</div>
<div class='item' style='float:right'>
</div>
</div>
</div>

<div class='row column tree-holder' id='tree-holder'>
<div class='tree-content-holder' id='tree-content-holder'>
<div class='file_holder'>
<div class='file_title'>
<div class='blob-description'>
<i class='octicon octicon-book'></i>
<span class='file_name'>
Rbac.class.php
<small>9.9 KB</small>
</span>
→
<span class='recent-commit' style='margin-top: 0.7rem'>
<a href="/hdmzy" class="commit-author-link">410004417@qq.com</a>
<span>提交于</span>
<span class='timeago commit-date' title='2015-04-07 10:04:02 +0800'>
2015-04-07 10:04
</span>
<a href="/hdmzy/c47_teacher/commit/3e97da5059c52ed9a2119ffda7959ddcc8bb6d4c">2015年4月7日10:04:00</a>
</span>

</div>
<span class='options'><div class='ui mini buttons basic'>
<textarea id="blob_raw" name="blob_raw" style="display:none;">
&lt;?php&#x000A;// .-----------------------------------------------------------------------------------&#x000A;// |  Software: [HDPHP framework]&#x000A;// |   Version: 2013.01&#x000A;// |      Site: http://www.hdphp.com&#x000A;// |-----------------------------------------------------------------------------------&#x000A;// |    Author: 向军 &lt;2300071698@qq.com&gt;&#x000A;// | Copyright (c) 2012-2013, http://houdunwang.com. All Rights Reserved.&#x000A;// |-----------------------------------------------------------------------------------&#x000A;// |   License: http://www.apache.org/licenses/LICENSE-2.0&#x000A;// &#x27;-----------------------------------------------------------------------------------&#x000A;&#x000A;/**&#x000A; * RBAC基于角色的权限控制&#x000A; * @package     tools_class&#x000A; * @author      后盾向军 &lt;houdunwangxj@gmail.com&gt;&#x000A; */&#x000A;final class Rbac&#x000A;{&#x000A;&#x000A;    static public $error; //错误信息&#x000A;&#x000A;    /**&#x000A;     * 获得所有RBAC表，自动根据配置文件处理，加表前缀&#x000A;     * @return array&#x000A;     */&#x000A;&#x000A;    static private function getRbacTable()&#x000A;    {&#x000A;        $tableName = array(&#x000A;            &quot;RBAC_USER_TABLE&quot;, &quot;RBAC_ROLE_TABLE&quot;, &quot;RBAC_NODE_TABLE&quot;, &quot;RBAC_ROLE_USER_TABLE&quot;, &quot;access_table&quot;&#x000A;        );&#x000A;        $preFix = C(&quot;DB_PREFIX&quot;);&#x000A;        $tables = array();&#x000A;        foreach ($tableName as $name) {&#x000A;            $table = C($name);&#x000A;            if (strpos($preFix, $name) !== 0) {&#x000A;                $table = $preFix . $table;&#x000A;            }&#x000A;            $tables[$name] = $table;&#x000A;        }&#x000A;        return $tables;&#x000A;    }&#x000A;&#x000A;    /**&#x000A;     * 根据SESSION值验证用户是否登录&#x000A;     * @return boolean&#x000A;     */&#x000A;    static public function isLogin()&#x000A;    {&#x000A;        return session(C(&quot;RBAC_AUTH_KEY&quot;)) ? true : false;&#x000A;    }&#x000A;&#x000A;    /**&#x000A;     * 用户登录操作&#x000A;     * 用户登录成功后将权限信息写入$_SESSION&#x000A;     * 如果用户登录成功并且用户名与$superadmin参数相同，此用户即为超级用户，不受任何访问权限限制&#x000A;     * @param string $username              用户名&#x000A;     * @param string $password              密码&#x000A;     * @param string $superadmin            超级管理员帐号&#x000A;     * @param string $fieldUserName         用户表中的用户名字段名称&#x000A;     * @param string $fieldPassword         用户表中的密码字段名称&#x000A;     * @return boolean&#x000A;     */&#x000A;    static public function login($username, $password, $superadmin = null, $fieldUserName = null, $fieldPassword = null)&#x000A;    {&#x000A;        $superadmin = is_null($superadmin) ? C(&quot;RBAC_SUPER_ADMIN&quot;) : $superadmin;&#x000A;        $fieldUserName = is_null($fieldUserName) ? C(&quot;RBAC_USERNAME_FIELD&quot;) : $fieldUserName; //用户表中的用户名字段名称&#x000A;        $fieldPassword = is_null($fieldPassword) ? C(&quot;RBAC_PASSWORD_FIELD&quot;) : $fieldPassword; //用户表中的密码字段名称&#x000A;        if (!C(&quot;RBAC_USER_TABLE&quot;)) {&#x000A;            halt(&#x27;用户表设置错误，请在配置文件中添加用户表&#x27;);&#x000A;        }&#x000A;        $table_user = C(&#x27;DB_PREFIX&#x27;) . str_ireplace(C(&#x27;DB_PREFIX&#x27;), &quot;&quot;, C(&quot;RBAC_USER_TABLE&quot;)); //验证有无前缀得到用户表&#x000A;        $db = M($table_user, true);&#x000A;        $user = $db-&gt;find(&quot;$fieldUserName=&#x27;$username&#x27;&quot;);&#x000A;&#x000A;        if (!$user) {&#x000A;            self::$error = &#x27;用户不存在&#x27;;&#x000A;            return false;&#x000A;        }&#x000A;        if ($user[$fieldPassword] != $password) {&#x000A;            self::$error = &#x27;密码输入错误&#x27;;&#x000A;            return false;&#x000A;        }&#x000A;        $uid = C(&quot;RBAC_AUTH_KEY&quot;);//验证session中的key&#x000A;        $db-&gt;table(C(&quot;RBAC_ROLE_USER_TABLE&quot;));&#x000A;        $sql = &quot;SELECT * FROM &quot; . C(&quot;DB_PREFIX&quot;) . C(&quot;RBAC_ROLE_TABLE&quot;) . &quot; AS r,&quot; .&#x000A;            C(&#x27;DB_PREFIX&#x27;) . C(&#x27;RBAC_ROLE_USER_TABLE&#x27;) .&#x000A;            &quot; AS r_u WHERE r_u.rid = r.rid AND {$uid} = &#x27;&quot; .&#x000A;            $user[$uid] . &quot;&#x27;&quot;;&#x000A;&#x000A;        $userRoleInfo = $db-&gt;query($sql); //获得用户组信息&#x000A;&#x000A;        $_SESSION[&#x27;username&#x27;] = $user[&#x27;username&#x27;];&#x000A;        $_SESSION[C(&quot;RBAC_AUTH_KEY&quot;)] = $user[$uid];&#x000A;        $_SESSION[&#x27;role&#x27;] = isset($userRoleInfo[0][&#x27;rname&#x27;]) ? $userRoleInfo[0][&#x27;rname&#x27;] : &#x27;&#x27;;&#x000A;        $_SESSION[&#x27;rid&#x27;] =isset($userRoleInfo[0][&#x27;rid&#x27;]) ? $userRoleInfo[0][&#x27;rid&#x27;] : &#x27;&#x27;;&#x000A;        //是否判断超管理员&#x000A;        if (strtoupper($user[&#x27;username&#x27;]) == strtoupper($superadmin)) {&#x000A;            //登录成功&#x000A;            $_SESSION[C(&quot;RBAC_SUPER_ADMIN&quot;)] = 1;&#x000A;            $_SESSION[&quot;RBAC&quot;] = array();&#x000A;            return true;&#x000A;        }&#x000A;        if (!$_SESSION[&#x27;rid&#x27;]) { //不属于任何角色&#x000A;            self::$error = &#x27;不属于任何组，没有访问权限&#x27;;&#x000A;            return false;&#x000A;        }&#x000A;        self::getAccess(); //获得权限写入SESSION&#x000A;        return true;&#x000A;    }&#x000A;&#x000A;    /**&#x000A;     * 将rbac信息保存到$_SESSION中&#x000A;     * $_SESSION[&#x27;RBAC&#x27;] 权限数据组&#x000A;     */&#x000A;    static private function getAccess()&#x000A;    {&#x000A;        //清空原RBAC数据&#x000A;        if (isset($_SESSION[&#x27;RBAC&#x27;])) {&#x000A;            $_SESSION[&#x27;RBAC&#x27;] = &#x27;&#x27;;&#x000A;        }&#x000A;        $table = self::getRbacTable(); //获得所有RBAC表&#x000A;        $nodeTable = $table[&#x27;RBAC_NODE_TABLE&#x27;]; //节点表&#x000A;        $accessTable = $table[&#x27;access_table&#x27;]; //权限表&#x000A;        $roleTable = $table[&#x27;RBAC_ROLE_TABLE&#x27;]; //角色表&#x000A;        $rid = intval($_SESSION[&#x27;rid&#x27;]); //角色ID&#x000A;        //数据库权限&#x000A;        $sql = &quot;SELECT  n.nid AS n_nid, n.name AS n_name, &quot; .&#x000A;            &quot;n.title AS n_title,n.level AS n_level, n.pid AS n_pid &quot; .&#x000A;            &quot;FROM &quot; . $nodeTable . &quot; AS n &quot; .&#x000A;            &quot;INNER JOIN &quot; . $accessTable . &quot; AS a ON n.nid = a.nid &quot; .&#x000A;            &quot;INNER JOIN &quot; . $roleTable . &quot; AS r ON r.rid = a.rid &quot; .&#x000A;            &quot;WHERE a.rid =&quot; . $rid . &quot; AND n.state =1 &quot; .&#x000A;            &quot;AND r.state =1 &quot; .&#x000A;            &quot;ORDER BY n.level,n.sort&quot;;&#x000A;        $info = M()-&gt;query($sql);&#x000A;        if (!$info)&#x000A;            return false;&#x000A;        $accessNode = array_change_value_case($info);&#x000A;        $access = array();&#x000A;        foreach ($accessNode as $v) {&#x000A;            if ($v[&#x27;n_level&#x27;] == 1) {&#x000A;                $access[$v[&#x27;n_name&#x27;]] = array();&#x000A;                foreach ($info as $n) {&#x000A;                    if ($n[&#x27;n_pid&#x27;] == $v[&#x27;n_nid&#x27;]) {&#x000A;                        $access[$v[&#x27;n_name&#x27;]][$n[&#x27;n_name&#x27;]] = array();&#x000A;                        foreach ($info as $j) {&#x000A;                            if ($j[&#x27;n_pid&#x27;] == $n[&#x27;n_nid&#x27;]) {&#x000A;                                $access[$v[&#x27;n_name&#x27;]][$n[&#x27;n_name&#x27;]][] = $j[&quot;n_name&quot;];&#x000A;                            }&#x000A;                        }&#x000A;                    }&#x000A;                }&#x000A;            }&#x000A;        }&#x000A;        $_SESSION[&quot;RBAC&quot;] = array_change_key_case_d(array_change_value_case($access)); //将权限保存到SESSION&#x000A;        return true;&#x000A;    }&#x000A;&#x000A;    /**&#x000A;     * 获得角色所有节点&#x000A;     * @param int $rid 角色ID，角色id如果传值将获得角色的所有权限信息&#x000A;     * @return array&#x000A;     */&#x000A;    static public function getNodeList($rid = null)&#x000A;    {&#x000A;        $table = self::getRbacTable(); //获得所有RBAC表&#x000A;        $nodeTable = $table[&#x27;RBAC_NODE_TABLE&#x27;]; //节点表&#x000A;        $accessTable = $table[&#x27;access_table&#x27;]; //权限表&#x000A;        $where = $rid ? &quot; WHERE rid =$rid&quot; : &quot;&quot;;&#x000A;        $sql = &quot;SELECT n.nid,n.name ,n.title,n.state,n.pid ,n.level, &quot; .&#x000A;            &quot; a.rid AS rid FROM &quot; .&#x000A;            $nodeTable . &quot; AS n &quot; .&#x000A;            &quot;LEFT JOIN (select * from $accessTable  $where) AS a &quot; .&#x000A;            &quot;ON n.nid = a.nid &quot; .&#x000A;            &quot;ORDER BY n.level,n.sort ASC&quot;;&#x000A;        $data = M()-&gt;query($sql);&#x000A;        if (!$data)&#x000A;            return array();&#x000A;        $nodes = array(); //组合后的节点&#x000A;        foreach ($data as $n) {&#x000A;            if ($n[&#x27;level&#x27;] == 1) {&#x000A;                $nodes[$n[&#x27;nid&#x27;]] = $n;&#x000A;                $nodes[$n[&#x27;nid&#x27;]][&#x27;node&#x27;] = array();&#x000A;                foreach ($data as $m) {&#x000A;                    if ($n[&#x27;nid&#x27;] == $m[&#x27;pid&#x27;]) {&#x000A;                        $nodes[$n[&#x27;nid&#x27;]][&#x27;node&#x27;][$m[&#x27;nid&#x27;]] = $m;&#x000A;                        $nodes[$n[&#x27;nid&#x27;]][&#x27;node&#x27;][$m[&#x27;nid&#x27;]][&#x27;node&#x27;] = array();&#x000A;                        foreach ($data as $c) {&#x000A;                            if ($m[&#x27;nid&#x27;] == $c[&#x27;pid&#x27;]) {&#x000A;                                $nodes[$n[&#x27;nid&#x27;]][&#x27;node&#x27;][$m[&#x27;nid&#x27;]][&#x27;node&#x27;][$c[&#x27;nid&#x27;]] = $c;&#x000A;                            }&#x000A;                        }&#x000A;                    }&#x000A;                }&#x000A;            }&#x000A;        }&#x000A;        return array_change_key_case_d(array_change_value_case($nodes));&#x000A;    }&#x000A;&#x000A;    /**&#x000A;     * 验证用户访问权限&#x000A;     * @return boolean&#x000A;     */&#x000A;    static public function checkAccess()&#x000A;    {&#x000A;&#x000A;&#x000A;        //不验证标识&#x000A;        if (isset($_SESSION[C(&quot;RBAC_SUPER_ADMIN&quot;)]) &amp;&amp; !empty($_SESSION[C(&quot;RBAC_SUPER_ADMIN&quot;)]))&#x000A;            return true;&#x000A;    &#x000A;        //不需要验证&#x000A;        if (self::noAuth()) {&#x000A;            return true;&#x000A;        }&#x000A;&#x000A;        //没有登录&#x000A;        if (!isset($_SESSION[C(&#x27;RBAC_AUTH_KEY&#x27;)])) {&#x000A;            return false;&#x000A;        }&#x000A;        //时时认证&#x000A;        if (C(&quot;RBAC_TYPE&quot;) == 1) {&#x000A;            self::getAccess();&#x000A;        }&#x000A;        //不需要验证的方法 例app/control/method&#x000A;        if (self::noAuth()) {&#x000A;            return true;&#x000A;        }&#x000A;        //如果不存在RBAC内容 不验证返回&#x000A;        if (!isset($_SESSION[&#x27;RBAC&#x27;]) || empty($_SESSION[&#x27;RBAC&#x27;])) {&#x000A;            return false;&#x000A;        }&#x000A;        $access = $_SESSION[&#x27;RBAC&#x27;];&#x000A;        if (!is_array($access)) {&#x000A;            return false;&#x000A;        }&#x000A;        $_app = strtolower(MODULE);&#x000A;        $_control = strtolower(CONTROLLER);&#x000A;        $_method = strtolower(ACTION);&#x000A;        if (array_key_exists_d($_app, $access)) {&#x000A;            if (array_key_exists_d($_control, $access[$_app])) {&#x000A;                if (in_array($_method, $access[$_app][$_control])) {&#x000A;                    return true;&#x000A;                }&#x000A;            }&#x000A;        }&#x000A;        return false;&#x000A;    }&#x000A;&#x000A;    //检测不需要验证的方法&#x000A;    static private function noAuth()&#x000A;    {&#x000A;        $noAuth = C(&quot;RBAC_NO_AUTH&quot;);&#x000A;        if (empty($noAuth) || !is_array($noAuth)) {&#x000A;            return false;&#x000A;        }&#x000A;        foreach ($noAuth as $v) {&#x000A;            $arr = preg_split(&quot;/\||\//&quot;, $v);&#x000A;            if (count($arr) != 2) {&#x000A;                error(&quot;配置项:RBAC_NO_AUTH 设置错误必须为[控制器/方法]格式&quot;, false);&#x000A;            }&#x000A;            if (strtolower(CONTROLLER) == strtolower($arr[0]) AND strtolower(ACTION) == strtolower($arr[1])) {&#x000A;                return true;&#x000A;            }&#x000A;        }&#x000A;        return false;&#x000A;    }&#x000A;&#x000A;}</textarea>
<a href="#" class="ui button" id="copy-text">一键复制</a>
<a href="/hdmzy/c47_teacher/edit/master/%E5%A4%A7%E9%A1%B9%E7%9B%AE/Rbac.class.php" class="ui button disabled has_tooltip" title="无编辑权限">编辑</a>
<a href="/hdmzy/c47_teacher/raw/master/%E5%A4%A7%E9%A1%B9%E7%9B%AE/Rbac.class.php" class="ui button">原始数据</a>
<a href="/hdmzy/c47_teacher/blame/master/%E5%A4%A7%E9%A1%B9%E7%9B%AE/Rbac.class.php" class="ui button">按行查看</a>
<a href="/hdmzy/c47_teacher/commits/master/%E5%A4%A7%E9%A1%B9%E7%9B%AE/Rbac.class.php" class="ui button">历史</a>
</div>
<script>
  $(document).ready(function(){
    $('#copy-text').popup({content:'点击复制', on: 'hover', delay: { show: 200, hide: 200 }});
     $('#copy-text').zclip({
        path:'/ZeroClipboard.swf',
        copy:$('#blob_raw').val(),
        clickAfter:false,
        afterCopy:function(){
          $("#copy-text").popup({content:'已复制'});
          $("#copy-text").popup('show');
        },
        beforeCopy:function(){
          $("#copy-text").popup('hide');
        }
     });
  });
</script>
</span>
</div>
<div class='clearfix'></div>
<div class='file_content code'>
<div class='lines white'>
<div class='line-numbers'><a href='#L1' id='L1' rel='#L#1'><i class='icon-link'></i>1</a><a href='#L2' id='L2' rel='#L#2'><i class='icon-link'></i>2</a><a href='#L3' id='L3' rel='#L#3'><i class='icon-link'></i>3</a><a href='#L4' id='L4' rel='#L#4'><i class='icon-link'></i>4</a><a href='#L5' id='L5' rel='#L#5'><i class='icon-link'></i>5</a><a href='#L6' id='L6' rel='#L#6'><i class='icon-link'></i>6</a><a href='#L7' id='L7' rel='#L#7'><i class='icon-link'></i>7</a><a href='#L8' id='L8' rel='#L#8'><i class='icon-link'></i>8</a><a href='#L9' id='L9' rel='#L#9'><i class='icon-link'></i>9</a><a href='#L10' id='L10' rel='#L#10'><i class='icon-link'></i>10</a><a href='#L11' id='L11' rel='#L#11'><i class='icon-link'></i>11</a><a href='#L12' id='L12' rel='#L#12'><i class='icon-link'></i>12</a><a href='#L13' id='L13' rel='#L#13'><i class='icon-link'></i>13</a><a href='#L14' id='L14' rel='#L#14'><i class='icon-link'></i>14</a><a href='#L15' id='L15' rel='#L#15'><i class='icon-link'></i>15</a><a href='#L16' id='L16' rel='#L#16'><i class='icon-link'></i>16</a><a href='#L17' id='L17' rel='#L#17'><i class='icon-link'></i>17</a><a href='#L18' id='L18' rel='#L#18'><i class='icon-link'></i>18</a><a href='#L19' id='L19' rel='#L#19'><i class='icon-link'></i>19</a><a href='#L20' id='L20' rel='#L#20'><i class='icon-link'></i>20</a><a href='#L21' id='L21' rel='#L#21'><i class='icon-link'></i>21</a><a href='#L22' id='L22' rel='#L#22'><i class='icon-link'></i>22</a><a href='#L23' id='L23' rel='#L#23'><i class='icon-link'></i>23</a><a href='#L24' id='L24' rel='#L#24'><i class='icon-link'></i>24</a><a href='#L25' id='L25' rel='#L#25'><i class='icon-link'></i>25</a><a href='#L26' id='L26' rel='#L#26'><i class='icon-link'></i>26</a><a href='#L27' id='L27' rel='#L#27'><i class='icon-link'></i>27</a><a href='#L28' id='L28' rel='#L#28'><i class='icon-link'></i>28</a><a href='#L29' id='L29' rel='#L#29'><i class='icon-link'></i>29</a><a href='#L30' id='L30' rel='#L#30'><i class='icon-link'></i>30</a><a href='#L31' id='L31' rel='#L#31'><i class='icon-link'></i>31</a><a href='#L32' id='L32' rel='#L#32'><i class='icon-link'></i>32</a><a href='#L33' id='L33' rel='#L#33'><i class='icon-link'></i>33</a><a href='#L34' id='L34' rel='#L#34'><i class='icon-link'></i>34</a><a href='#L35' id='L35' rel='#L#35'><i class='icon-link'></i>35</a><a href='#L36' id='L36' rel='#L#36'><i class='icon-link'></i>36</a><a href='#L37' id='L37' rel='#L#37'><i class='icon-link'></i>37</a><a href='#L38' id='L38' rel='#L#38'><i class='icon-link'></i>38</a><a href='#L39' id='L39' rel='#L#39'><i class='icon-link'></i>39</a><a href='#L40' id='L40' rel='#L#40'><i class='icon-link'></i>40</a><a href='#L41' id='L41' rel='#L#41'><i class='icon-link'></i>41</a><a href='#L42' id='L42' rel='#L#42'><i class='icon-link'></i>42</a><a href='#L43' id='L43' rel='#L#43'><i class='icon-link'></i>43</a><a href='#L44' id='L44' rel='#L#44'><i class='icon-link'></i>44</a><a href='#L45' id='L45' rel='#L#45'><i class='icon-link'></i>45</a><a href='#L46' id='L46' rel='#L#46'><i class='icon-link'></i>46</a><a href='#L47' id='L47' rel='#L#47'><i class='icon-link'></i>47</a><a href='#L48' id='L48' rel='#L#48'><i class='icon-link'></i>48</a><a href='#L49' id='L49' rel='#L#49'><i class='icon-link'></i>49</a><a href='#L50' id='L50' rel='#L#50'><i class='icon-link'></i>50</a><a href='#L51' id='L51' rel='#L#51'><i class='icon-link'></i>51</a><a href='#L52' id='L52' rel='#L#52'><i class='icon-link'></i>52</a><a href='#L53' id='L53' rel='#L#53'><i class='icon-link'></i>53</a><a href='#L54' id='L54' rel='#L#54'><i class='icon-link'></i>54</a><a href='#L55' id='L55' rel='#L#55'><i class='icon-link'></i>55</a><a href='#L56' id='L56' rel='#L#56'><i class='icon-link'></i>56</a><a href='#L57' id='L57' rel='#L#57'><i class='icon-link'></i>57</a><a href='#L58' id='L58' rel='#L#58'><i class='icon-link'></i>58</a><a href='#L59' id='L59' rel='#L#59'><i class='icon-link'></i>59</a><a href='#L60' id='L60' rel='#L#60'><i class='icon-link'></i>60</a><a href='#L61' id='L61' rel='#L#61'><i class='icon-link'></i>61</a><a href='#L62' id='L62' rel='#L#62'><i class='icon-link'></i>62</a><a href='#L63' id='L63' rel='#L#63'><i class='icon-link'></i>63</a><a href='#L64' id='L64' rel='#L#64'><i class='icon-link'></i>64</a><a href='#L65' id='L65' rel='#L#65'><i class='icon-link'></i>65</a><a href='#L66' id='L66' rel='#L#66'><i class='icon-link'></i>66</a><a href='#L67' id='L67' rel='#L#67'><i class='icon-link'></i>67</a><a href='#L68' id='L68' rel='#L#68'><i class='icon-link'></i>68</a><a href='#L69' id='L69' rel='#L#69'><i class='icon-link'></i>69</a><a href='#L70' id='L70' rel='#L#70'><i class='icon-link'></i>70</a><a href='#L71' id='L71' rel='#L#71'><i class='icon-link'></i>71</a><a href='#L72' id='L72' rel='#L#72'><i class='icon-link'></i>72</a><a href='#L73' id='L73' rel='#L#73'><i class='icon-link'></i>73</a><a href='#L74' id='L74' rel='#L#74'><i class='icon-link'></i>74</a><a href='#L75' id='L75' rel='#L#75'><i class='icon-link'></i>75</a><a href='#L76' id='L76' rel='#L#76'><i class='icon-link'></i>76</a><a href='#L77' id='L77' rel='#L#77'><i class='icon-link'></i>77</a><a href='#L78' id='L78' rel='#L#78'><i class='icon-link'></i>78</a><a href='#L79' id='L79' rel='#L#79'><i class='icon-link'></i>79</a><a href='#L80' id='L80' rel='#L#80'><i class='icon-link'></i>80</a><a href='#L81' id='L81' rel='#L#81'><i class='icon-link'></i>81</a><a href='#L82' id='L82' rel='#L#82'><i class='icon-link'></i>82</a><a href='#L83' id='L83' rel='#L#83'><i class='icon-link'></i>83</a><a href='#L84' id='L84' rel='#L#84'><i class='icon-link'></i>84</a><a href='#L85' id='L85' rel='#L#85'><i class='icon-link'></i>85</a><a href='#L86' id='L86' rel='#L#86'><i class='icon-link'></i>86</a><a href='#L87' id='L87' rel='#L#87'><i class='icon-link'></i>87</a><a href='#L88' id='L88' rel='#L#88'><i class='icon-link'></i>88</a><a href='#L89' id='L89' rel='#L#89'><i class='icon-link'></i>89</a><a href='#L90' id='L90' rel='#L#90'><i class='icon-link'></i>90</a><a href='#L91' id='L91' rel='#L#91'><i class='icon-link'></i>91</a><a href='#L92' id='L92' rel='#L#92'><i class='icon-link'></i>92</a><a href='#L93' id='L93' rel='#L#93'><i class='icon-link'></i>93</a><a href='#L94' id='L94' rel='#L#94'><i class='icon-link'></i>94</a><a href='#L95' id='L95' rel='#L#95'><i class='icon-link'></i>95</a><a href='#L96' id='L96' rel='#L#96'><i class='icon-link'></i>96</a><a href='#L97' id='L97' rel='#L#97'><i class='icon-link'></i>97</a><a href='#L98' id='L98' rel='#L#98'><i class='icon-link'></i>98</a><a href='#L99' id='L99' rel='#L#99'><i class='icon-link'></i>99</a><a href='#L100' id='L100' rel='#L#100'><i class='icon-link'></i>100</a><a href='#L101' id='L101' rel='#L#101'><i class='icon-link'></i>101</a><a href='#L102' id='L102' rel='#L#102'><i class='icon-link'></i>102</a><a href='#L103' id='L103' rel='#L#103'><i class='icon-link'></i>103</a><a href='#L104' id='L104' rel='#L#104'><i class='icon-link'></i>104</a><a href='#L105' id='L105' rel='#L#105'><i class='icon-link'></i>105</a><a href='#L106' id='L106' rel='#L#106'><i class='icon-link'></i>106</a><a href='#L107' id='L107' rel='#L#107'><i class='icon-link'></i>107</a><a href='#L108' id='L108' rel='#L#108'><i class='icon-link'></i>108</a><a href='#L109' id='L109' rel='#L#109'><i class='icon-link'></i>109</a><a href='#L110' id='L110' rel='#L#110'><i class='icon-link'></i>110</a><a href='#L111' id='L111' rel='#L#111'><i class='icon-link'></i>111</a><a href='#L112' id='L112' rel='#L#112'><i class='icon-link'></i>112</a><a href='#L113' id='L113' rel='#L#113'><i class='icon-link'></i>113</a><a href='#L114' id='L114' rel='#L#114'><i class='icon-link'></i>114</a><a href='#L115' id='L115' rel='#L#115'><i class='icon-link'></i>115</a><a href='#L116' id='L116' rel='#L#116'><i class='icon-link'></i>116</a><a href='#L117' id='L117' rel='#L#117'><i class='icon-link'></i>117</a><a href='#L118' id='L118' rel='#L#118'><i class='icon-link'></i>118</a><a href='#L119' id='L119' rel='#L#119'><i class='icon-link'></i>119</a><a href='#L120' id='L120' rel='#L#120'><i class='icon-link'></i>120</a><a href='#L121' id='L121' rel='#L#121'><i class='icon-link'></i>121</a><a href='#L122' id='L122' rel='#L#122'><i class='icon-link'></i>122</a><a href='#L123' id='L123' rel='#L#123'><i class='icon-link'></i>123</a><a href='#L124' id='L124' rel='#L#124'><i class='icon-link'></i>124</a><a href='#L125' id='L125' rel='#L#125'><i class='icon-link'></i>125</a><a href='#L126' id='L126' rel='#L#126'><i class='icon-link'></i>126</a><a href='#L127' id='L127' rel='#L#127'><i class='icon-link'></i>127</a><a href='#L128' id='L128' rel='#L#128'><i class='icon-link'></i>128</a><a href='#L129' id='L129' rel='#L#129'><i class='icon-link'></i>129</a><a href='#L130' id='L130' rel='#L#130'><i class='icon-link'></i>130</a><a href='#L131' id='L131' rel='#L#131'><i class='icon-link'></i>131</a><a href='#L132' id='L132' rel='#L#132'><i class='icon-link'></i>132</a><a href='#L133' id='L133' rel='#L#133'><i class='icon-link'></i>133</a><a href='#L134' id='L134' rel='#L#134'><i class='icon-link'></i>134</a><a href='#L135' id='L135' rel='#L#135'><i class='icon-link'></i>135</a><a href='#L136' id='L136' rel='#L#136'><i class='icon-link'></i>136</a><a href='#L137' id='L137' rel='#L#137'><i class='icon-link'></i>137</a><a href='#L138' id='L138' rel='#L#138'><i class='icon-link'></i>138</a><a href='#L139' id='L139' rel='#L#139'><i class='icon-link'></i>139</a><a href='#L140' id='L140' rel='#L#140'><i class='icon-link'></i>140</a><a href='#L141' id='L141' rel='#L#141'><i class='icon-link'></i>141</a><a href='#L142' id='L142' rel='#L#142'><i class='icon-link'></i>142</a><a href='#L143' id='L143' rel='#L#143'><i class='icon-link'></i>143</a><a href='#L144' id='L144' rel='#L#144'><i class='icon-link'></i>144</a><a href='#L145' id='L145' rel='#L#145'><i class='icon-link'></i>145</a><a href='#L146' id='L146' rel='#L#146'><i class='icon-link'></i>146</a><a href='#L147' id='L147' rel='#L#147'><i class='icon-link'></i>147</a><a href='#L148' id='L148' rel='#L#148'><i class='icon-link'></i>148</a><a href='#L149' id='L149' rel='#L#149'><i class='icon-link'></i>149</a><a href='#L150' id='L150' rel='#L#150'><i class='icon-link'></i>150</a><a href='#L151' id='L151' rel='#L#151'><i class='icon-link'></i>151</a><a href='#L152' id='L152' rel='#L#152'><i class='icon-link'></i>152</a><a href='#L153' id='L153' rel='#L#153'><i class='icon-link'></i>153</a><a href='#L154' id='L154' rel='#L#154'><i class='icon-link'></i>154</a><a href='#L155' id='L155' rel='#L#155'><i class='icon-link'></i>155</a><a href='#L156' id='L156' rel='#L#156'><i class='icon-link'></i>156</a><a href='#L157' id='L157' rel='#L#157'><i class='icon-link'></i>157</a><a href='#L158' id='L158' rel='#L#158'><i class='icon-link'></i>158</a><a href='#L159' id='L159' rel='#L#159'><i class='icon-link'></i>159</a><a href='#L160' id='L160' rel='#L#160'><i class='icon-link'></i>160</a><a href='#L161' id='L161' rel='#L#161'><i class='icon-link'></i>161</a><a href='#L162' id='L162' rel='#L#162'><i class='icon-link'></i>162</a><a href='#L163' id='L163' rel='#L#163'><i class='icon-link'></i>163</a><a href='#L164' id='L164' rel='#L#164'><i class='icon-link'></i>164</a><a href='#L165' id='L165' rel='#L#165'><i class='icon-link'></i>165</a><a href='#L166' id='L166' rel='#L#166'><i class='icon-link'></i>166</a><a href='#L167' id='L167' rel='#L#167'><i class='icon-link'></i>167</a><a href='#L168' id='L168' rel='#L#168'><i class='icon-link'></i>168</a><a href='#L169' id='L169' rel='#L#169'><i class='icon-link'></i>169</a><a href='#L170' id='L170' rel='#L#170'><i class='icon-link'></i>170</a><a href='#L171' id='L171' rel='#L#171'><i class='icon-link'></i>171</a><a href='#L172' id='L172' rel='#L#172'><i class='icon-link'></i>172</a><a href='#L173' id='L173' rel='#L#173'><i class='icon-link'></i>173</a><a href='#L174' id='L174' rel='#L#174'><i class='icon-link'></i>174</a><a href='#L175' id='L175' rel='#L#175'><i class='icon-link'></i>175</a><a href='#L176' id='L176' rel='#L#176'><i class='icon-link'></i>176</a><a href='#L177' id='L177' rel='#L#177'><i class='icon-link'></i>177</a><a href='#L178' id='L178' rel='#L#178'><i class='icon-link'></i>178</a><a href='#L179' id='L179' rel='#L#179'><i class='icon-link'></i>179</a><a href='#L180' id='L180' rel='#L#180'><i class='icon-link'></i>180</a><a href='#L181' id='L181' rel='#L#181'><i class='icon-link'></i>181</a><a href='#L182' id='L182' rel='#L#182'><i class='icon-link'></i>182</a><a href='#L183' id='L183' rel='#L#183'><i class='icon-link'></i>183</a><a href='#L184' id='L184' rel='#L#184'><i class='icon-link'></i>184</a><a href='#L185' id='L185' rel='#L#185'><i class='icon-link'></i>185</a><a href='#L186' id='L186' rel='#L#186'><i class='icon-link'></i>186</a><a href='#L187' id='L187' rel='#L#187'><i class='icon-link'></i>187</a><a href='#L188' id='L188' rel='#L#188'><i class='icon-link'></i>188</a><a href='#L189' id='L189' rel='#L#189'><i class='icon-link'></i>189</a><a href='#L190' id='L190' rel='#L#190'><i class='icon-link'></i>190</a><a href='#L191' id='L191' rel='#L#191'><i class='icon-link'></i>191</a><a href='#L192' id='L192' rel='#L#192'><i class='icon-link'></i>192</a><a href='#L193' id='L193' rel='#L#193'><i class='icon-link'></i>193</a><a href='#L194' id='L194' rel='#L#194'><i class='icon-link'></i>194</a><a href='#L195' id='L195' rel='#L#195'><i class='icon-link'></i>195</a><a href='#L196' id='L196' rel='#L#196'><i class='icon-link'></i>196</a><a href='#L197' id='L197' rel='#L#197'><i class='icon-link'></i>197</a><a href='#L198' id='L198' rel='#L#198'><i class='icon-link'></i>198</a><a href='#L199' id='L199' rel='#L#199'><i class='icon-link'></i>199</a><a href='#L200' id='L200' rel='#L#200'><i class='icon-link'></i>200</a><a href='#L201' id='L201' rel='#L#201'><i class='icon-link'></i>201</a><a href='#L202' id='L202' rel='#L#202'><i class='icon-link'></i>202</a><a href='#L203' id='L203' rel='#L#203'><i class='icon-link'></i>203</a><a href='#L204' id='L204' rel='#L#204'><i class='icon-link'></i>204</a><a href='#L205' id='L205' rel='#L#205'><i class='icon-link'></i>205</a><a href='#L206' id='L206' rel='#L#206'><i class='icon-link'></i>206</a><a href='#L207' id='L207' rel='#L#207'><i class='icon-link'></i>207</a><a href='#L208' id='L208' rel='#L#208'><i class='icon-link'></i>208</a><a href='#L209' id='L209' rel='#L#209'><i class='icon-link'></i>209</a><a href='#L210' id='L210' rel='#L#210'><i class='icon-link'></i>210</a><a href='#L211' id='L211' rel='#L#211'><i class='icon-link'></i>211</a><a href='#L212' id='L212' rel='#L#212'><i class='icon-link'></i>212</a><a href='#L213' id='L213' rel='#L#213'><i class='icon-link'></i>213</a><a href='#L214' id='L214' rel='#L#214'><i class='icon-link'></i>214</a><a href='#L215' id='L215' rel='#L#215'><i class='icon-link'></i>215</a><a href='#L216' id='L216' rel='#L#216'><i class='icon-link'></i>216</a><a href='#L217' id='L217' rel='#L#217'><i class='icon-link'></i>217</a><a href='#L218' id='L218' rel='#L#218'><i class='icon-link'></i>218</a><a href='#L219' id='L219' rel='#L#219'><i class='icon-link'></i>219</a><a href='#L220' id='L220' rel='#L#220'><i class='icon-link'></i>220</a><a href='#L221' id='L221' rel='#L#221'><i class='icon-link'></i>221</a><a href='#L222' id='L222' rel='#L#222'><i class='icon-link'></i>222</a><a href='#L223' id='L223' rel='#L#223'><i class='icon-link'></i>223</a><a href='#L224' id='L224' rel='#L#224'><i class='icon-link'></i>224</a><a href='#L225' id='L225' rel='#L#225'><i class='icon-link'></i>225</a><a href='#L226' id='L226' rel='#L#226'><i class='icon-link'></i>226</a><a href='#L227' id='L227' rel='#L#227'><i class='icon-link'></i>227</a><a href='#L228' id='L228' rel='#L#228'><i class='icon-link'></i>228</a><a href='#L229' id='L229' rel='#L#229'><i class='icon-link'></i>229</a><a href='#L230' id='L230' rel='#L#230'><i class='icon-link'></i>230</a><a href='#L231' id='L231' rel='#L#231'><i class='icon-link'></i>231</a><a href='#L232' id='L232' rel='#L#232'><i class='icon-link'></i>232</a><a href='#L233' id='L233' rel='#L#233'><i class='icon-link'></i>233</a><a href='#L234' id='L234' rel='#L#234'><i class='icon-link'></i>234</a><a href='#L235' id='L235' rel='#L#235'><i class='icon-link'></i>235</a><a href='#L236' id='L236' rel='#L#236'><i class='icon-link'></i>236</a><a href='#L237' id='L237' rel='#L#237'><i class='icon-link'></i>237</a><a href='#L238' id='L238' rel='#L#238'><i class='icon-link'></i>238</a><a href='#L239' id='L239' rel='#L#239'><i class='icon-link'></i>239</a><a href='#L240' id='L240' rel='#L#240'><i class='icon-link'></i>240</a><a href='#L241' id='L241' rel='#L#241'><i class='icon-link'></i>241</a><a href='#L242' id='L242' rel='#L#242'><i class='icon-link'></i>242</a><a href='#L243' id='L243' rel='#L#243'><i class='icon-link'></i>243</a><a href='#L244' id='L244' rel='#L#244'><i class='icon-link'></i>244</a><a href='#L245' id='L245' rel='#L#245'><i class='icon-link'></i>245</a><a href='#L246' id='L246' rel='#L#246'><i class='icon-link'></i>246</a><a href='#L247' id='L247' rel='#L#247'><i class='icon-link'></i>247</a><a href='#L248' id='L248' rel='#L#248'><i class='icon-link'></i>248</a><a href='#L249' id='L249' rel='#L#249'><i class='icon-link'></i>249</a><a href='#L250' id='L250' rel='#L#250'><i class='icon-link'></i>250</a><a href='#L251' id='L251' rel='#L#251'><i class='icon-link'></i>251</a><a href='#L252' id='L252' rel='#L#252'><i class='icon-link'></i>252</a><a href='#L253' id='L253' rel='#L#253'><i class='icon-link'></i>253</a><a href='#L254' id='L254' rel='#L#254'><i class='icon-link'></i>254</a><a href='#L255' id='L255' rel='#L#255'><i class='icon-link'></i>255</a><a href='#L256' id='L256' rel='#L#256'><i class='icon-link'></i>256</a><a href='#L257' id='L257' rel='#L#257'><i class='icon-link'></i>257</a><a href='#L258' id='L258' rel='#L#258'><i class='icon-link'></i>258</a><a href='#L259' id='L259' rel='#L#259'><i class='icon-link'></i>259</a><a href='#L260' id='L260' rel='#L#260'><i class='icon-link'></i>260</a><a href='#L261' id='L261' rel='#L#261'><i class='icon-link'></i>261</a><a href='#L262' id='L262' rel='#L#262'><i class='icon-link'></i>262</a><a href='#L263' id='L263' rel='#L#263'><i class='icon-link'></i>263</a><a href='#L264' id='L264' rel='#L#264'><i class='icon-link'></i>264</a><a href='#L265' id='L265' rel='#L#265'><i class='icon-link'></i>265</a><a href='#L266' id='L266' rel='#L#266'><i class='icon-link'></i>266</a><a href='#L267' id='L267' rel='#L#267'><i class='icon-link'></i>267</a><a href='#L268' id='L268' rel='#L#268'><i class='icon-link'></i>268</a><a href='#L269' id='L269' rel='#L#269'><i class='icon-link'></i>269</a><a href='#L270' id='L270' rel='#L#270'><i class='icon-link'></i>270</a><a href='#L271' id='L271' rel='#L#271'><i class='icon-link'></i>271</a></div><div class='highlight'><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span>
</div><div class='line' id='LC2'><span class="c1">// .-----------------------------------------------------------------------------------
</div><div class='line' id='LC3'>// |  Software: [HDPHP framework]
</div><div class='line' id='LC4'>// |   Version: 2013.01
</div><div class='line' id='LC5'>// |      Site: http://www.hdphp.com
</div><div class='line' id='LC6'>// |-----------------------------------------------------------------------------------
</div><div class='line' id='LC7'>// |    Author: 向军 &lt;2300071698@qq.com&gt;
</div><div class='line' id='LC8'>// | Copyright (c) 2012-2013, http://houdunwang.com. All Rights Reserved.
</div><div class='line' id='LC9'>// |-----------------------------------------------------------------------------------
</div><div class='line' id='LC10'>// |   License: http://www.apache.org/licenses/LICENSE-2.0
</div><div class='line' id='LC11'>// '-----------------------------------------------------------------------------------
</div><div class='line' id='LC12'></span>
</div><div class='line' id='LC13'><span class="sd">/**
</div><div class='line' id='LC14'> * RBAC基于角色的权限控制
</div><div class='line' id='LC15'> * @package     tools_class
</div><div class='line' id='LC16'> * @author      后盾向军 &lt;houdunwangxj@gmail.com&gt;
</div><div class='line' id='LC17'> */</span>
</div><div class='line' id='LC18'><span class="k">final</span> <span class="k">class</span> <span class="nc">Rbac</span>
</div><div class='line' id='LC19'><span class="p">{</span>
</div><div class='line' id='LC20'>
</div><div class='line' id='LC21'>    <span class="k">static</span> <span class="k">public</span> <span class="nv">$error</span><span class="p">;</span> <span class="c1">//错误信息
</div><div class='line' id='LC22'></span>
</div><div class='line' id='LC23'>    <span class="sd">/**
</div><div class='line' id='LC24'>     * 获得所有RBAC表，自动根据配置文件处理，加表前缀
</div><div class='line' id='LC25'>     * @return array
</div><div class='line' id='LC26'>     */</span>
</div><div class='line' id='LC27'>
</div><div class='line' id='LC28'>    <span class="k">static</span> <span class="k">private</span> <span class="k">function</span> <span class="nf">getRbacTable</span><span class="p">()</span>
</div><div class='line' id='LC29'>    <span class="p">{</span>
</div><div class='line' id='LC30'>        <span class="nv">$tableName</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
</div><div class='line' id='LC31'>            <span class="s2">"RBAC_USER_TABLE"</span><span class="p">,</span> <span class="s2">"RBAC_ROLE_TABLE"</span><span class="p">,</span> <span class="s2">"RBAC_NODE_TABLE"</span><span class="p">,</span> <span class="s2">"RBAC_ROLE_USER_TABLE"</span><span class="p">,</span> <span class="s2">"access_table"</span>
</div><div class='line' id='LC32'>        <span class="p">);</span>
</div><div class='line' id='LC33'>        <span class="nv">$preFix</span> <span class="o">=</span> <span class="nx">C</span><span class="p">(</span><span class="s2">"DB_PREFIX"</span><span class="p">);</span>
</div><div class='line' id='LC34'>        <span class="nv">$tables</span> <span class="o">=</span> <span class="k">array</span><span class="p">();</span>
</div><div class='line' id='LC35'>        <span class="k">foreach</span> <span class="p">(</span><span class="nv">$tableName</span> <span class="k">as</span> <span class="nv">$name</span><span class="p">)</span> <span class="p">{</span>
</div><div class='line' id='LC36'>            <span class="nv">$table</span> <span class="o">=</span> <span class="nx">C</span><span class="p">(</span><span class="nv">$name</span><span class="p">);</span>
</div><div class='line' id='LC37'>            <span class="k">if</span> <span class="p">(</span><span class="nb">strpos</span><span class="p">(</span><span class="nv">$preFix</span><span class="p">,</span> <span class="nv">$name</span><span class="p">)</span> <span class="o">!==</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
</div><div class='line' id='LC38'>                <span class="nv">$table</span> <span class="o">=</span> <span class="nv">$preFix</span> <span class="o">.</span> <span class="nv">$table</span><span class="p">;</span>
</div><div class='line' id='LC39'>            <span class="p">}</span>
</div><div class='line' id='LC40'>            <span class="nv">$tables</span><span class="p">[</span><span class="nv">$name</span><span class="p">]</span> <span class="o">=</span> <span class="nv">$table</span><span class="p">;</span>
</div><div class='line' id='LC41'>        <span class="p">}</span>
</div><div class='line' id='LC42'>        <span class="k">return</span> <span class="nv">$tables</span><span class="p">;</span>
</div><div class='line' id='LC43'>    <span class="p">}</span>
</div><div class='line' id='LC44'>
</div><div class='line' id='LC45'>    <span class="sd">/**
</div><div class='line' id='LC46'>     * 根据SESSION值验证用户是否登录
</div><div class='line' id='LC47'>     * @return boolean
</div><div class='line' id='LC48'>     */</span>
</div><div class='line' id='LC49'>    <span class="k">static</span> <span class="k">public</span> <span class="k">function</span> <span class="nf">isLogin</span><span class="p">()</span>
</div><div class='line' id='LC50'>    <span class="p">{</span>
</div><div class='line' id='LC51'>        <span class="k">return</span> <span class="nx">session</span><span class="p">(</span><span class="nx">C</span><span class="p">(</span><span class="s2">"RBAC_AUTH_KEY"</span><span class="p">))</span> <span class="o">?</span> <span class="kc">true</span> <span class="o">:</span> <span class="kc">false</span><span class="p">;</span>
</div><div class='line' id='LC52'>    <span class="p">}</span>
</div><div class='line' id='LC53'>
</div><div class='line' id='LC54'>    <span class="sd">/**
</div><div class='line' id='LC55'>     * 用户登录操作
</div><div class='line' id='LC56'>     * 用户登录成功后将权限信息写入$_SESSION
</div><div class='line' id='LC57'>     * 如果用户登录成功并且用户名与$superadmin参数相同，此用户即为超级用户，不受任何访问权限限制
</div><div class='line' id='LC58'>     * @param string $username              用户名
</div><div class='line' id='LC59'>     * @param string $password              密码
</div><div class='line' id='LC60'>     * @param string $superadmin            超级管理员帐号
</div><div class='line' id='LC61'>     * @param string $fieldUserName         用户表中的用户名字段名称
</div><div class='line' id='LC62'>     * @param string $fieldPassword         用户表中的密码字段名称
</div><div class='line' id='LC63'>     * @return boolean
</div><div class='line' id='LC64'>     */</span>
</div><div class='line' id='LC65'>    <span class="k">static</span> <span class="k">public</span> <span class="k">function</span> <span class="nf">login</span><span class="p">(</span><span class="nv">$username</span><span class="p">,</span> <span class="nv">$password</span><span class="p">,</span> <span class="nv">$superadmin</span> <span class="o">=</span> <span class="kc">null</span><span class="p">,</span> <span class="nv">$fieldUserName</span> <span class="o">=</span> <span class="kc">null</span><span class="p">,</span> <span class="nv">$fieldPassword</span> <span class="o">=</span> <span class="kc">null</span><span class="p">)</span>
</div><div class='line' id='LC66'>    <span class="p">{</span>
</div><div class='line' id='LC67'>        <span class="nv">$superadmin</span> <span class="o">=</span> <span class="nb">is_null</span><span class="p">(</span><span class="nv">$superadmin</span><span class="p">)</span> <span class="o">?</span> <span class="nx">C</span><span class="p">(</span><span class="s2">"RBAC_SUPER_ADMIN"</span><span class="p">)</span> <span class="o">:</span> <span class="nv">$superadmin</span><span class="p">;</span>
</div><div class='line' id='LC68'>        <span class="nv">$fieldUserName</span> <span class="o">=</span> <span class="nb">is_null</span><span class="p">(</span><span class="nv">$fieldUserName</span><span class="p">)</span> <span class="o">?</span> <span class="nx">C</span><span class="p">(</span><span class="s2">"RBAC_USERNAME_FIELD"</span><span class="p">)</span> <span class="o">:</span> <span class="nv">$fieldUserName</span><span class="p">;</span> <span class="c1">//用户表中的用户名字段名称
</div><div class='line' id='LC69'></span>        <span class="nv">$fieldPassword</span> <span class="o">=</span> <span class="nb">is_null</span><span class="p">(</span><span class="nv">$fieldPassword</span><span class="p">)</span> <span class="o">?</span> <span class="nx">C</span><span class="p">(</span><span class="s2">"RBAC_PASSWORD_FIELD"</span><span class="p">)</span> <span class="o">:</span> <span class="nv">$fieldPassword</span><span class="p">;</span> <span class="c1">//用户表中的密码字段名称
</div><div class='line' id='LC70'></span>        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">C</span><span class="p">(</span><span class="s2">"RBAC_USER_TABLE"</span><span class="p">))</span> <span class="p">{</span>
</div><div class='line' id='LC71'>            <span class="nx">halt</span><span class="p">(</span><span class="s1">'用户表设置错误，请在配置文件中添加用户表'</span><span class="p">);</span>
</div><div class='line' id='LC72'>        <span class="p">}</span>
</div><div class='line' id='LC73'>        <span class="nv">$table_user</span> <span class="o">=</span> <span class="nx">C</span><span class="p">(</span><span class="s1">'DB_PREFIX'</span><span class="p">)</span> <span class="o">.</span> <span class="nb">str_ireplace</span><span class="p">(</span><span class="nx">C</span><span class="p">(</span><span class="s1">'DB_PREFIX'</span><span class="p">),</span> <span class="s2">""</span><span class="p">,</span> <span class="nx">C</span><span class="p">(</span><span class="s2">"RBAC_USER_TABLE"</span><span class="p">));</span> <span class="c1">//验证有无前缀得到用户表
</div><div class='line' id='LC74'></span>        <span class="nv">$db</span> <span class="o">=</span> <span class="nx">M</span><span class="p">(</span><span class="nv">$table_user</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
</div><div class='line' id='LC75'>        <span class="nv">$user</span> <span class="o">=</span> <span class="nv">$db</span><span class="o">-&gt;</span><span class="na">find</span><span class="p">(</span><span class="s2">"</span><span class="nv">$fieldUserName</span><span class="s2">='</span><span class="nv">$username</span><span class="s2">'"</span><span class="p">);</span>
</div><div class='line' id='LC76'>
</div><div class='line' id='LC77'>        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nv">$user</span><span class="p">)</span> <span class="p">{</span>
</div><div class='line' id='LC78'>            <span class="nx">self</span><span class="o">::</span><span class="nv">$error</span> <span class="o">=</span> <span class="s1">'用户不存在'</span><span class="p">;</span>
</div><div class='line' id='LC79'>            <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</div><div class='line' id='LC80'>        <span class="p">}</span>
</div><div class='line' id='LC81'>        <span class="k">if</span> <span class="p">(</span><span class="nv">$user</span><span class="p">[</span><span class="nv">$fieldPassword</span><span class="p">]</span> <span class="o">!=</span> <span class="nv">$password</span><span class="p">)</span> <span class="p">{</span>
</div><div class='line' id='LC82'>            <span class="nx">self</span><span class="o">::</span><span class="nv">$error</span> <span class="o">=</span> <span class="s1">'密码输入错误'</span><span class="p">;</span>
</div><div class='line' id='LC83'>            <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</div><div class='line' id='LC84'>        <span class="p">}</span>
</div><div class='line' id='LC85'>        <span class="nv">$uid</span> <span class="o">=</span> <span class="nx">C</span><span class="p">(</span><span class="s2">"RBAC_AUTH_KEY"</span><span class="p">);</span><span class="c1">//验证session中的key
</div><div class='line' id='LC86'></span>        <span class="nv">$db</span><span class="o">-&gt;</span><span class="na">table</span><span class="p">(</span><span class="nx">C</span><span class="p">(</span><span class="s2">"RBAC_ROLE_USER_TABLE"</span><span class="p">));</span>
</div><div class='line' id='LC87'>        <span class="nv">$sql</span> <span class="o">=</span> <span class="s2">"SELECT * FROM "</span> <span class="o">.</span> <span class="nx">C</span><span class="p">(</span><span class="s2">"DB_PREFIX"</span><span class="p">)</span> <span class="o">.</span> <span class="nx">C</span><span class="p">(</span><span class="s2">"RBAC_ROLE_TABLE"</span><span class="p">)</span> <span class="o">.</span> <span class="s2">" AS r,"</span> <span class="o">.</span>
</div><div class='line' id='LC88'>            <span class="nx">C</span><span class="p">(</span><span class="s1">'DB_PREFIX'</span><span class="p">)</span> <span class="o">.</span> <span class="nx">C</span><span class="p">(</span><span class="s1">'RBAC_ROLE_USER_TABLE'</span><span class="p">)</span> <span class="o">.</span>
</div><div class='line' id='LC89'>            <span class="s2">" AS r_u WHERE r_u.rid = r.rid AND </span><span class="si">{</span><span class="nv">$uid</span><span class="si">}</span><span class="s2"> = '"</span> <span class="o">.</span>
</div><div class='line' id='LC90'>            <span class="nv">$user</span><span class="p">[</span><span class="nv">$uid</span><span class="p">]</span> <span class="o">.</span> <span class="s2">"'"</span><span class="p">;</span>
</div><div class='line' id='LC91'>
</div><div class='line' id='LC92'>        <span class="nv">$userRoleInfo</span> <span class="o">=</span> <span class="nv">$db</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="nv">$sql</span><span class="p">);</span> <span class="c1">//获得用户组信息
</div><div class='line' id='LC93'></span>
</div><div class='line' id='LC94'>        <span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">'username'</span><span class="p">]</span> <span class="o">=</span> <span class="nv">$user</span><span class="p">[</span><span class="s1">'username'</span><span class="p">];</span>
</div><div class='line' id='LC95'>        <span class="nv">$_SESSION</span><span class="p">[</span><span class="nx">C</span><span class="p">(</span><span class="s2">"RBAC_AUTH_KEY"</span><span class="p">)]</span> <span class="o">=</span> <span class="nv">$user</span><span class="p">[</span><span class="nv">$uid</span><span class="p">];</span>
</div><div class='line' id='LC96'>        <span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">'role'</span><span class="p">]</span> <span class="o">=</span> <span class="nb">isset</span><span class="p">(</span><span class="nv">$userRoleInfo</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s1">'rname'</span><span class="p">])</span> <span class="o">?</span> <span class="nv">$userRoleInfo</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s1">'rname'</span><span class="p">]</span> <span class="o">:</span> <span class="s1">''</span><span class="p">;</span>
</div><div class='line' id='LC97'>        <span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">'rid'</span><span class="p">]</span> <span class="o">=</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$userRoleInfo</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s1">'rid'</span><span class="p">])</span> <span class="o">?</span> <span class="nv">$userRoleInfo</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s1">'rid'</span><span class="p">]</span> <span class="o">:</span> <span class="s1">''</span><span class="p">;</span>
</div><div class='line' id='LC98'>        <span class="c1">//是否判断超管理员
</div><div class='line' id='LC99'></span>        <span class="k">if</span> <span class="p">(</span><span class="nb">strtoupper</span><span class="p">(</span><span class="nv">$user</span><span class="p">[</span><span class="s1">'username'</span><span class="p">])</span> <span class="o">==</span> <span class="nb">strtoupper</span><span class="p">(</span><span class="nv">$superadmin</span><span class="p">))</span> <span class="p">{</span>
</div><div class='line' id='LC100'>            <span class="c1">//登录成功
</div><div class='line' id='LC101'></span>            <span class="nv">$_SESSION</span><span class="p">[</span><span class="nx">C</span><span class="p">(</span><span class="s2">"RBAC_SUPER_ADMIN"</span><span class="p">)]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
</div><div class='line' id='LC102'>            <span class="nv">$_SESSION</span><span class="p">[</span><span class="s2">"RBAC"</span><span class="p">]</span> <span class="o">=</span> <span class="k">array</span><span class="p">();</span>
</div><div class='line' id='LC103'>            <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
</div><div class='line' id='LC104'>        <span class="p">}</span>
</div><div class='line' id='LC105'>        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">'rid'</span><span class="p">])</span> <span class="p">{</span> <span class="c1">//不属于任何角色
</div><div class='line' id='LC106'></span>            <span class="nx">self</span><span class="o">::</span><span class="nv">$error</span> <span class="o">=</span> <span class="s1">'不属于任何组，没有访问权限'</span><span class="p">;</span>
</div><div class='line' id='LC107'>            <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</div><div class='line' id='LC108'>        <span class="p">}</span>
</div><div class='line' id='LC109'>        <span class="nx">self</span><span class="o">::</span><span class="na">getAccess</span><span class="p">();</span> <span class="c1">//获得权限写入SESSION
</div><div class='line' id='LC110'></span>        <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
</div><div class='line' id='LC111'>    <span class="p">}</span>
</div><div class='line' id='LC112'>
</div><div class='line' id='LC113'>    <span class="sd">/**
</div><div class='line' id='LC114'>     * 将rbac信息保存到$_SESSION中
</div><div class='line' id='LC115'>     * $_SESSION['RBAC'] 权限数据组
</div><div class='line' id='LC116'>     */</span>
</div><div class='line' id='LC117'>    <span class="k">static</span> <span class="k">private</span> <span class="k">function</span> <span class="nf">getAccess</span><span class="p">()</span>
</div><div class='line' id='LC118'>    <span class="p">{</span>
</div><div class='line' id='LC119'>        <span class="c1">//清空原RBAC数据
</div><div class='line' id='LC120'></span>        <span class="k">if</span> <span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">'RBAC'</span><span class="p">]))</span> <span class="p">{</span>
</div><div class='line' id='LC121'>            <span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">'RBAC'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">''</span><span class="p">;</span>
</div><div class='line' id='LC122'>        <span class="p">}</span>
</div><div class='line' id='LC123'>        <span class="nv">$table</span> <span class="o">=</span> <span class="nx">self</span><span class="o">::</span><span class="na">getRbacTable</span><span class="p">();</span> <span class="c1">//获得所有RBAC表
</div><div class='line' id='LC124'></span>        <span class="nv">$nodeTable</span> <span class="o">=</span> <span class="nv">$table</span><span class="p">[</span><span class="s1">'RBAC_NODE_TABLE'</span><span class="p">];</span> <span class="c1">//节点表
</div><div class='line' id='LC125'></span>        <span class="nv">$accessTable</span> <span class="o">=</span> <span class="nv">$table</span><span class="p">[</span><span class="s1">'access_table'</span><span class="p">];</span> <span class="c1">//权限表
</div><div class='line' id='LC126'></span>        <span class="nv">$roleTable</span> <span class="o">=</span> <span class="nv">$table</span><span class="p">[</span><span class="s1">'RBAC_ROLE_TABLE'</span><span class="p">];</span> <span class="c1">//角色表
</div><div class='line' id='LC127'></span>        <span class="nv">$rid</span> <span class="o">=</span> <span class="nb">intval</span><span class="p">(</span><span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">'rid'</span><span class="p">]);</span> <span class="c1">//角色ID
</div><div class='line' id='LC128'></span>        <span class="c1">//数据库权限
</div><div class='line' id='LC129'></span>        <span class="nv">$sql</span> <span class="o">=</span> <span class="s2">"SELECT  n.nid AS n_nid, n.name AS n_name, "</span> <span class="o">.</span>
</div><div class='line' id='LC130'>            <span class="s2">"n.title AS n_title,n.level AS n_level, n.pid AS n_pid "</span> <span class="o">.</span>
</div><div class='line' id='LC131'>            <span class="s2">"FROM "</span> <span class="o">.</span> <span class="nv">$nodeTable</span> <span class="o">.</span> <span class="s2">" AS n "</span> <span class="o">.</span>
</div><div class='line' id='LC132'>            <span class="s2">"INNER JOIN "</span> <span class="o">.</span> <span class="nv">$accessTable</span> <span class="o">.</span> <span class="s2">" AS a ON n.nid = a.nid "</span> <span class="o">.</span>
</div><div class='line' id='LC133'>            <span class="s2">"INNER JOIN "</span> <span class="o">.</span> <span class="nv">$roleTable</span> <span class="o">.</span> <span class="s2">" AS r ON r.rid = a.rid "</span> <span class="o">.</span>
</div><div class='line' id='LC134'>            <span class="s2">"WHERE a.rid ="</span> <span class="o">.</span> <span class="nv">$rid</span> <span class="o">.</span> <span class="s2">" AND n.state =1 "</span> <span class="o">.</span>
</div><div class='line' id='LC135'>            <span class="s2">"AND r.state =1 "</span> <span class="o">.</span>
</div><div class='line' id='LC136'>            <span class="s2">"ORDER BY n.level,n.sort"</span><span class="p">;</span>
</div><div class='line' id='LC137'>        <span class="nv">$info</span> <span class="o">=</span> <span class="nx">M</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="nv">$sql</span><span class="p">);</span>
</div><div class='line' id='LC138'>        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nv">$info</span><span class="p">)</span>
</div><div class='line' id='LC139'>            <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</div><div class='line' id='LC140'>        <span class="nv">$accessNode</span> <span class="o">=</span> <span class="nx">array_change_value_case</span><span class="p">(</span><span class="nv">$info</span><span class="p">);</span>
</div><div class='line' id='LC141'>        <span class="nv">$access</span> <span class="o">=</span> <span class="k">array</span><span class="p">();</span>
</div><div class='line' id='LC142'>        <span class="k">foreach</span> <span class="p">(</span><span class="nv">$accessNode</span> <span class="k">as</span> <span class="nv">$v</span><span class="p">)</span> <span class="p">{</span>
</div><div class='line' id='LC143'>            <span class="k">if</span> <span class="p">(</span><span class="nv">$v</span><span class="p">[</span><span class="s1">'n_level'</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
</div><div class='line' id='LC144'>                <span class="nv">$access</span><span class="p">[</span><span class="nv">$v</span><span class="p">[</span><span class="s1">'n_name'</span><span class="p">]]</span> <span class="o">=</span> <span class="k">array</span><span class="p">();</span>
</div><div class='line' id='LC145'>                <span class="k">foreach</span> <span class="p">(</span><span class="nv">$info</span> <span class="k">as</span> <span class="nv">$n</span><span class="p">)</span> <span class="p">{</span>
</div><div class='line' id='LC146'>                    <span class="k">if</span> <span class="p">(</span><span class="nv">$n</span><span class="p">[</span><span class="s1">'n_pid'</span><span class="p">]</span> <span class="o">==</span> <span class="nv">$v</span><span class="p">[</span><span class="s1">'n_nid'</span><span class="p">])</span> <span class="p">{</span>
</div><div class='line' id='LC147'>                        <span class="nv">$access</span><span class="p">[</span><span class="nv">$v</span><span class="p">[</span><span class="s1">'n_name'</span><span class="p">]][</span><span class="nv">$n</span><span class="p">[</span><span class="s1">'n_name'</span><span class="p">]]</span> <span class="o">=</span> <span class="k">array</span><span class="p">();</span>
</div><div class='line' id='LC148'>                        <span class="k">foreach</span> <span class="p">(</span><span class="nv">$info</span> <span class="k">as</span> <span class="nv">$j</span><span class="p">)</span> <span class="p">{</span>
</div><div class='line' id='LC149'>                            <span class="k">if</span> <span class="p">(</span><span class="nv">$j</span><span class="p">[</span><span class="s1">'n_pid'</span><span class="p">]</span> <span class="o">==</span> <span class="nv">$n</span><span class="p">[</span><span class="s1">'n_nid'</span><span class="p">])</span> <span class="p">{</span>
</div><div class='line' id='LC150'>                                <span class="nv">$access</span><span class="p">[</span><span class="nv">$v</span><span class="p">[</span><span class="s1">'n_name'</span><span class="p">]][</span><span class="nv">$n</span><span class="p">[</span><span class="s1">'n_name'</span><span class="p">]][]</span> <span class="o">=</span> <span class="nv">$j</span><span class="p">[</span><span class="s2">"n_name"</span><span class="p">];</span>
</div><div class='line' id='LC151'>                            <span class="p">}</span>
</div><div class='line' id='LC152'>                        <span class="p">}</span>
</div><div class='line' id='LC153'>                    <span class="p">}</span>
</div><div class='line' id='LC154'>                <span class="p">}</span>
</div><div class='line' id='LC155'>            <span class="p">}</span>
</div><div class='line' id='LC156'>        <span class="p">}</span>
</div><div class='line' id='LC157'>        <span class="nv">$_SESSION</span><span class="p">[</span><span class="s2">"RBAC"</span><span class="p">]</span> <span class="o">=</span> <span class="nx">array_change_key_case_d</span><span class="p">(</span><span class="nx">array_change_value_case</span><span class="p">(</span><span class="nv">$access</span><span class="p">));</span> <span class="c1">//将权限保存到SESSION
</div><div class='line' id='LC158'></span>        <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
</div><div class='line' id='LC159'>    <span class="p">}</span>
</div><div class='line' id='LC160'>
</div><div class='line' id='LC161'>    <span class="sd">/**
</div><div class='line' id='LC162'>     * 获得角色所有节点
</div><div class='line' id='LC163'>     * @param int $rid 角色ID，角色id如果传值将获得角色的所有权限信息
</div><div class='line' id='LC164'>     * @return array
</div><div class='line' id='LC165'>     */</span>
</div><div class='line' id='LC166'>    <span class="k">static</span> <span class="k">public</span> <span class="k">function</span> <span class="nf">getNodeList</span><span class="p">(</span><span class="nv">$rid</span> <span class="o">=</span> <span class="kc">null</span><span class="p">)</span>
</div><div class='line' id='LC167'>    <span class="p">{</span>
</div><div class='line' id='LC168'>        <span class="nv">$table</span> <span class="o">=</span> <span class="nx">self</span><span class="o">::</span><span class="na">getRbacTable</span><span class="p">();</span> <span class="c1">//获得所有RBAC表
</div><div class='line' id='LC169'></span>        <span class="nv">$nodeTable</span> <span class="o">=</span> <span class="nv">$table</span><span class="p">[</span><span class="s1">'RBAC_NODE_TABLE'</span><span class="p">];</span> <span class="c1">//节点表
</div><div class='line' id='LC170'></span>        <span class="nv">$accessTable</span> <span class="o">=</span> <span class="nv">$table</span><span class="p">[</span><span class="s1">'access_table'</span><span class="p">];</span> <span class="c1">//权限表
</div><div class='line' id='LC171'></span>        <span class="nv">$where</span> <span class="o">=</span> <span class="nv">$rid</span> <span class="o">?</span> <span class="s2">" WHERE rid =</span><span class="nv">$rid</span><span class="s2">"</span> <span class="o">:</span> <span class="s2">""</span><span class="p">;</span>
</div><div class='line' id='LC172'>        <span class="nv">$sql</span> <span class="o">=</span> <span class="s2">"SELECT n.nid,n.name ,n.title,n.state,n.pid ,n.level, "</span> <span class="o">.</span>
</div><div class='line' id='LC173'>            <span class="s2">" a.rid AS rid FROM "</span> <span class="o">.</span>
</div><div class='line' id='LC174'>            <span class="nv">$nodeTable</span> <span class="o">.</span> <span class="s2">" AS n "</span> <span class="o">.</span>
</div><div class='line' id='LC175'>            <span class="s2">"LEFT JOIN (select * from </span><span class="nv">$accessTable</span><span class="s2">  </span><span class="nv">$where</span><span class="s2">) AS a "</span> <span class="o">.</span>
</div><div class='line' id='LC176'>            <span class="s2">"ON n.nid = a.nid "</span> <span class="o">.</span>
</div><div class='line' id='LC177'>            <span class="s2">"ORDER BY n.level,n.sort ASC"</span><span class="p">;</span>
</div><div class='line' id='LC178'>        <span class="nv">$data</span> <span class="o">=</span> <span class="nx">M</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="nv">$sql</span><span class="p">);</span>
</div><div class='line' id='LC179'>        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nv">$data</span><span class="p">)</span>
</div><div class='line' id='LC180'>            <span class="k">return</span> <span class="k">array</span><span class="p">();</span>
</div><div class='line' id='LC181'>        <span class="nv">$nodes</span> <span class="o">=</span> <span class="k">array</span><span class="p">();</span> <span class="c1">//组合后的节点
</div><div class='line' id='LC182'></span>        <span class="k">foreach</span> <span class="p">(</span><span class="nv">$data</span> <span class="k">as</span> <span class="nv">$n</span><span class="p">)</span> <span class="p">{</span>
</div><div class='line' id='LC183'>            <span class="k">if</span> <span class="p">(</span><span class="nv">$n</span><span class="p">[</span><span class="s1">'level'</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
</div><div class='line' id='LC184'>                <span class="nv">$nodes</span><span class="p">[</span><span class="nv">$n</span><span class="p">[</span><span class="s1">'nid'</span><span class="p">]]</span> <span class="o">=</span> <span class="nv">$n</span><span class="p">;</span>
</div><div class='line' id='LC185'>                <span class="nv">$nodes</span><span class="p">[</span><span class="nv">$n</span><span class="p">[</span><span class="s1">'nid'</span><span class="p">]][</span><span class="s1">'node'</span><span class="p">]</span> <span class="o">=</span> <span class="k">array</span><span class="p">();</span>
</div><div class='line' id='LC186'>                <span class="k">foreach</span> <span class="p">(</span><span class="nv">$data</span> <span class="k">as</span> <span class="nv">$m</span><span class="p">)</span> <span class="p">{</span>
</div><div class='line' id='LC187'>                    <span class="k">if</span> <span class="p">(</span><span class="nv">$n</span><span class="p">[</span><span class="s1">'nid'</span><span class="p">]</span> <span class="o">==</span> <span class="nv">$m</span><span class="p">[</span><span class="s1">'pid'</span><span class="p">])</span> <span class="p">{</span>
</div><div class='line' id='LC188'>                        <span class="nv">$nodes</span><span class="p">[</span><span class="nv">$n</span><span class="p">[</span><span class="s1">'nid'</span><span class="p">]][</span><span class="s1">'node'</span><span class="p">][</span><span class="nv">$m</span><span class="p">[</span><span class="s1">'nid'</span><span class="p">]]</span> <span class="o">=</span> <span class="nv">$m</span><span class="p">;</span>
</div><div class='line' id='LC189'>                        <span class="nv">$nodes</span><span class="p">[</span><span class="nv">$n</span><span class="p">[</span><span class="s1">'nid'</span><span class="p">]][</span><span class="s1">'node'</span><span class="p">][</span><span class="nv">$m</span><span class="p">[</span><span class="s1">'nid'</span><span class="p">]][</span><span class="s1">'node'</span><span class="p">]</span> <span class="o">=</span> <span class="k">array</span><span class="p">();</span>
</div><div class='line' id='LC190'>                        <span class="k">foreach</span> <span class="p">(</span><span class="nv">$data</span> <span class="k">as</span> <span class="nv">$c</span><span class="p">)</span> <span class="p">{</span>
</div><div class='line' id='LC191'>                            <span class="k">if</span> <span class="p">(</span><span class="nv">$m</span><span class="p">[</span><span class="s1">'nid'</span><span class="p">]</span> <span class="o">==</span> <span class="nv">$c</span><span class="p">[</span><span class="s1">'pid'</span><span class="p">])</span> <span class="p">{</span>
</div><div class='line' id='LC192'>                                <span class="nv">$nodes</span><span class="p">[</span><span class="nv">$n</span><span class="p">[</span><span class="s1">'nid'</span><span class="p">]][</span><span class="s1">'node'</span><span class="p">][</span><span class="nv">$m</span><span class="p">[</span><span class="s1">'nid'</span><span class="p">]][</span><span class="s1">'node'</span><span class="p">][</span><span class="nv">$c</span><span class="p">[</span><span class="s1">'nid'</span><span class="p">]]</span> <span class="o">=</span> <span class="nv">$c</span><span class="p">;</span>
</div><div class='line' id='LC193'>                            <span class="p">}</span>
</div><div class='line' id='LC194'>                        <span class="p">}</span>
</div><div class='line' id='LC195'>                    <span class="p">}</span>
</div><div class='line' id='LC196'>                <span class="p">}</span>
</div><div class='line' id='LC197'>            <span class="p">}</span>
</div><div class='line' id='LC198'>        <span class="p">}</span>
</div><div class='line' id='LC199'>        <span class="k">return</span> <span class="nx">array_change_key_case_d</span><span class="p">(</span><span class="nx">array_change_value_case</span><span class="p">(</span><span class="nv">$nodes</span><span class="p">));</span>
</div><div class='line' id='LC200'>    <span class="p">}</span>
</div><div class='line' id='LC201'>
</div><div class='line' id='LC202'>    <span class="sd">/**
</div><div class='line' id='LC203'>     * 验证用户访问权限
</div><div class='line' id='LC204'>     * @return boolean
</div><div class='line' id='LC205'>     */</span>
</div><div class='line' id='LC206'>    <span class="k">static</span> <span class="k">public</span> <span class="k">function</span> <span class="nf">checkAccess</span><span class="p">()</span>
</div><div class='line' id='LC207'>    <span class="p">{</span>
</div><div class='line' id='LC208'>
</div><div class='line' id='LC209'>
</div><div class='line' id='LC210'>        <span class="c1">//不验证标识
</div><div class='line' id='LC211'></span>        <span class="k">if</span> <span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$_SESSION</span><span class="p">[</span><span class="nx">C</span><span class="p">(</span><span class="s2">"RBAC_SUPER_ADMIN"</span><span class="p">)])</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="k">empty</span><span class="p">(</span><span class="nv">$_SESSION</span><span class="p">[</span><span class="nx">C</span><span class="p">(</span><span class="s2">"RBAC_SUPER_ADMIN"</span><span class="p">)]))</span>
</div><div class='line' id='LC212'>            <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
</div><div class='line' id='LC213'>    
</div><div class='line' id='LC214'>        <span class="c1">//不需要验证
</div><div class='line' id='LC215'></span>        <span class="k">if</span> <span class="p">(</span><span class="nx">self</span><span class="o">::</span><span class="na">noAuth</span><span class="p">())</span> <span class="p">{</span>
</div><div class='line' id='LC216'>            <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
</div><div class='line' id='LC217'>        <span class="p">}</span>
</div><div class='line' id='LC218'>
</div><div class='line' id='LC219'>        <span class="c1">//没有登录
</div><div class='line' id='LC220'></span>        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$_SESSION</span><span class="p">[</span><span class="nx">C</span><span class="p">(</span><span class="s1">'RBAC_AUTH_KEY'</span><span class="p">)]))</span> <span class="p">{</span>
</div><div class='line' id='LC221'>            <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</div><div class='line' id='LC222'>        <span class="p">}</span>
</div><div class='line' id='LC223'>        <span class="c1">//时时认证
</div><div class='line' id='LC224'></span>        <span class="k">if</span> <span class="p">(</span><span class="nx">C</span><span class="p">(</span><span class="s2">"RBAC_TYPE"</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
</div><div class='line' id='LC225'>            <span class="nx">self</span><span class="o">::</span><span class="na">getAccess</span><span class="p">();</span>
</div><div class='line' id='LC226'>        <span class="p">}</span>
</div><div class='line' id='LC227'>        <span class="c1">//不需要验证的方法 例app/control/method
</div><div class='line' id='LC228'></span>        <span class="k">if</span> <span class="p">(</span><span class="nx">self</span><span class="o">::</span><span class="na">noAuth</span><span class="p">())</span> <span class="p">{</span>
</div><div class='line' id='LC229'>            <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
</div><div class='line' id='LC230'>        <span class="p">}</span>
</div><div class='line' id='LC231'>        <span class="c1">//如果不存在RBAC内容 不验证返回
</div><div class='line' id='LC232'></span>        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">'RBAC'</span><span class="p">])</span> <span class="o">||</span> <span class="k">empty</span><span class="p">(</span><span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">'RBAC'</span><span class="p">]))</span> <span class="p">{</span>
</div><div class='line' id='LC233'>            <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</div><div class='line' id='LC234'>        <span class="p">}</span>
</div><div class='line' id='LC235'>        <span class="nv">$access</span> <span class="o">=</span> <span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">'RBAC'</span><span class="p">];</span>
</div><div class='line' id='LC236'>        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nb">is_array</span><span class="p">(</span><span class="nv">$access</span><span class="p">))</span> <span class="p">{</span>
</div><div class='line' id='LC237'>            <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</div><div class='line' id='LC238'>        <span class="p">}</span>
</div><div class='line' id='LC239'>        <span class="nv">$_app</span> <span class="o">=</span> <span class="nb">strtolower</span><span class="p">(</span><span class="nx">MODULE</span><span class="p">);</span>
</div><div class='line' id='LC240'>        <span class="nv">$_control</span> <span class="o">=</span> <span class="nb">strtolower</span><span class="p">(</span><span class="nx">CONTROLLER</span><span class="p">);</span>
</div><div class='line' id='LC241'>        <span class="nv">$_method</span> <span class="o">=</span> <span class="nb">strtolower</span><span class="p">(</span><span class="nx">ACTION</span><span class="p">);</span>
</div><div class='line' id='LC242'>        <span class="k">if</span> <span class="p">(</span><span class="nx">array_key_exists_d</span><span class="p">(</span><span class="nv">$_app</span><span class="p">,</span> <span class="nv">$access</span><span class="p">))</span> <span class="p">{</span>
</div><div class='line' id='LC243'>            <span class="k">if</span> <span class="p">(</span><span class="nx">array_key_exists_d</span><span class="p">(</span><span class="nv">$_control</span><span class="p">,</span> <span class="nv">$access</span><span class="p">[</span><span class="nv">$_app</span><span class="p">]))</span> <span class="p">{</span>
</div><div class='line' id='LC244'>                <span class="k">if</span> <span class="p">(</span><span class="nb">in_array</span><span class="p">(</span><span class="nv">$_method</span><span class="p">,</span> <span class="nv">$access</span><span class="p">[</span><span class="nv">$_app</span><span class="p">][</span><span class="nv">$_control</span><span class="p">]))</span> <span class="p">{</span>
</div><div class='line' id='LC245'>                    <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
</div><div class='line' id='LC246'>                <span class="p">}</span>
</div><div class='line' id='LC247'>            <span class="p">}</span>
</div><div class='line' id='LC248'>        <span class="p">}</span>
</div><div class='line' id='LC249'>        <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</div><div class='line' id='LC250'>    <span class="p">}</span>
</div><div class='line' id='LC251'>
</div><div class='line' id='LC252'>    <span class="c1">//检测不需要验证的方法
</div><div class='line' id='LC253'></span>    <span class="k">static</span> <span class="k">private</span> <span class="k">function</span> <span class="nf">noAuth</span><span class="p">()</span>
</div><div class='line' id='LC254'>    <span class="p">{</span>
</div><div class='line' id='LC255'>        <span class="nv">$noAuth</span> <span class="o">=</span> <span class="nx">C</span><span class="p">(</span><span class="s2">"RBAC_NO_AUTH"</span><span class="p">);</span>
</div><div class='line' id='LC256'>        <span class="k">if</span> <span class="p">(</span><span class="k">empty</span><span class="p">(</span><span class="nv">$noAuth</span><span class="p">)</span> <span class="o">||</span> <span class="o">!</span><span class="nb">is_array</span><span class="p">(</span><span class="nv">$noAuth</span><span class="p">))</span> <span class="p">{</span>
</div><div class='line' id='LC257'>            <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</div><div class='line' id='LC258'>        <span class="p">}</span>
</div><div class='line' id='LC259'>        <span class="k">foreach</span> <span class="p">(</span><span class="nv">$noAuth</span> <span class="k">as</span> <span class="nv">$v</span><span class="p">)</span> <span class="p">{</span>
</div><div class='line' id='LC260'>            <span class="nv">$arr</span> <span class="o">=</span> <span class="nb">preg_split</span><span class="p">(</span><span class="s2">"/\||\//"</span><span class="p">,</span> <span class="nv">$v</span><span class="p">);</span>
</div><div class='line' id='LC261'>            <span class="k">if</span> <span class="p">(</span><span class="nb">count</span><span class="p">(</span><span class="nv">$arr</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">2</span><span class="p">)</span> <span class="p">{</span>
</div><div class='line' id='LC262'>                <span class="nx">error</span><span class="p">(</span><span class="s2">"配置项:RBAC_NO_AUTH 设置错误必须为[控制器/方法]格式"</span><span class="p">,</span> <span class="kc">false</span><span class="p">);</span>
</div><div class='line' id='LC263'>            <span class="p">}</span>
</div><div class='line' id='LC264'>            <span class="k">if</span> <span class="p">(</span><span class="nb">strtolower</span><span class="p">(</span><span class="nx">CONTROLLER</span><span class="p">)</span> <span class="o">==</span> <span class="nb">strtolower</span><span class="p">(</span><span class="nv">$arr</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="nx">AND</span> <span class="nb">strtolower</span><span class="p">(</span><span class="nx">ACTION</span><span class="p">)</span> <span class="o">==</span> <span class="nb">strtolower</span><span class="p">(</span><span class="nv">$arr</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span> <span class="p">{</span>
</div><div class='line' id='LC265'>                <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
</div><div class='line' id='LC266'>            <span class="p">}</span>
</div><div class='line' id='LC267'>        <span class="p">}</span>
</div><div class='line' id='LC268'>        <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</div><div class='line' id='LC269'>    <span class="p">}</span>
</div><div class='line' id='LC270'>
</div><div class='line' id='LC271'><span class="p">}</span><span class="w">
</div><div class='line' id='LC272'></span></div></pre></div>
</div>
</div>

</div>
</div>
<div class='tree_progress'></div>

</div>
</div>
<script>
  (function() {
    $(function() {
      return Tree.init();
    });
  
  }).call(this);
</script>

<script>
  Tree.initHighlightTheme('white')
</script>
<div id='gotop'></div>
<style>
  #gotop{
  display: none;
    width: 30px;
    height: 32px;
    position: fixed;
    right: 50px;
    cursor: pointer;
    bottom: 165px;
    border-radius: 10px;
    opacity: 3;
    background: url("/cd-top-arrow.svg") no-repeat 50% 50%;
    background-color: #bab3b2;
  }
</style>
<script>
  function goTop(){
    $(window).scroll(function(e) {
      if($(this).scrollTop()>50)
        $("#gotop").fadeIn(1000);
      else
        $("#gotop").fadeOut(1000);
    });
  };
  $(function(){
    $("#gotop").click(function(e) {
      $('body,html').animate({scrollTop:0},500);
    });
    goTop();
  });
</script>

<footer id='git-footer-main'>
<div class='ui grid page five column' id='git-footer'>
<div class='column'>
<div class='ui link list'>
<div class='item'>
<a href="/terms">使用条款</a>
</div>
<div class='item'>
<a href="/piracy">隐私与安全</a>
</div>
<div class='item'>
<a href="http://git.oschina.net/oschina/git-osc/wikis/%E5%B8%AE%E5%8A%A9#继续阅读">使用教程</a>
</div>
</div>
</div>
<div class='column'>
<div class='ui link list'>
<div class='item'>
<a href="http://git.oschina.net/oschina/git-osc/wikis/FAQ"><i class='icon help'></i>
FAQ
</a></div>
<div class='item'>
<a href="http://git.oschina.net/progit"><i class='icon git square'></i>
ProGit
</a></div>
<div class='item'></div>
</div>
</div>
<div class='column' id='oschina-link'>
<div class='ui link list'>
<div class='item'>
<a href="http://www.oschina.net/question?catalog=4">开源中国讨论区
</a></div>
<div class='item'>
<a href="mailto:market@oschina.net?Subject=osc@git问题收集">联系我们
</a></div>
<div class='item'>
<a href="http://www.oschina.net">© 2015 OSChina.NET
</a></div>
</div>
</div>
<div class='column' id='git-friend-link' style='width:140px'>
<a href="http://www.oschina.net" target="_blank"><img alt="Logo_s2" src="https://www.oschina.net/img/logo_s2.gif" />
</a><br>
<a href="http://www.51idc.com/" target="_blank"><img alt="51idc" src="/51idc.png" style="width: 75px; height: 20px" />
</a><br>
<a href="https://www.wosign.com/" target="_blank"><img alt="Wosign" src="/wosign.png" style="width: 90px; height: 25px" />
</a></div>
<div class='column' style='width:160px;padding-right:0;padding-left:30px'>
<div class='ui list'>
<div class='item' style='padding-top:15px;text-align:right;width:130px'>
<a href="/appclient" target="_blank">扫描下载手机APP →
</a></div>
<div class='item' style='padding-top:10px;text-align:center;width:130px'>
<a href="/appclient" target="_blank">Andriod & iPhone
</a></div>
</div>
</div>
<div class='column' style='width:120px;float:right'>
<div class='ui list'>
<div class='item' style='text-align:right;float:right'>
<a href="/appclient" target="_blank"><img alt="Appclient" src="/appclient.png" style="width: 80px; height: 80px" />
</a></div>
</div>
</div>
</div>
</footer>
<style>
  .ui.android.popup{
    width: 110px;
    height: 110px;
  }
  #git-footer{
    padding-left: 0;
    padding-right: 0;
  }
</style>

</body>
</html>
